#6  对一篇英文小说，进行词频统计，输出前20个出现频率最高的单词；


file = open("laoren.txt", encoding='utf-8')
word_appear_time = {}
for line in file:
    words = line.strip().split()
    for word in words:
        if word in word_appear_time:
            word_appear_time[word] += 1
        else:
            word_appear_time[word] = 1

word_list = []
for word, times in word_appear_time.items():
    word_list.append((times, word))

word_list.sort(reverse = True)
for times, word in word_list[:20]:
    print(word)
# 关闭文件句柄
file.close()